% orig code: https://zhuanlan.zhihu.com/p/471457420
function [C]=Bezier(varargin)
narginchk(1,3)
%只输入了控制点序列，返回整个曲线拟合点集合
if nargin==1
    C=Bezier_gen(varargin{1},0.001);
    return
end

%增加输入画图控制符
if nargin==2
    C=Bezier_gen(varargin{1},0.001);
    if varargin{2}
        %将拟合曲线和控制点绘制出来
        ShowCurveAndCtrls(C,varargin{1});
    end
    return
end

%增加输入比例系数t 返回t对应的拟合点
if nargin ==3
    P=Bezier_gen(varargin{1},0.001);
    t_s=varargin{3};
    C(:,1)=P(int16(t_s/0.001),1);
    C(:,2)=P(int16(t_s/0.001),2);

    if varargin{2}
        ShowCurveAndCtrls(P,varargin{1});
        hold on
        plot(C(1),C(2),'o','LineWidth',1,'MarkerEdgeColor','k',...
            'MarkerFaceColor','k','MarkerSize',6);
        xlabel('x','FontSize',20);
        ylabel('y','FontSize',20);
        ctrls=varargin{1};
        while size(ctrls,1)>1
            for i=1:size(ctrls,1)-1
                ctrls(i,:)=Bezier_1st(ctrls(i:i+1,:),t_s);
            end
            ctrls=ctrls(1:size(ctrls,1)-1,:);
        end
        ctrls=varargin{1};
        plot(ctrls(:,1),ctrls(:,2),'o','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',6);
    end
    return
end
end